/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.kamionowski.supreme.controllers.host;

import java.util.List;
import org.kamionowski.supreme.controllers.base.AbstractJsonController;
import org.kamionowski.supreme.persistence.dao.HostDAO;
import org.kamionowski.supreme.persistence.entity.Host;
import org.kamionowski.supreme.persistence.entity.HostIP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author soldier
 */
@RequestMapping(value="/host")
@Controller
public class HostController extends AbstractJsonController {

    @Autowired
    private HostDAO hostDAO;

    @RequestMapping(value="/all")
    public ModelAndView allHosts(){
        List<Host> hosts = hostDAO.getAllHosts();
        objects.put("hosts", hosts);
        return createJson();
    }

    @RequestMapping(value="/{hostName}/ip")
    public ModelAndView getHostIPs(@PathVariable("hostName") String hostName){
        List<HostIP> ips = hostDAO.getIPs(hostName);
        objects.put("hostname", hostName);
        objects.put("ip", ips);
        return createJson();
    }

    @RequestMapping(value="/{hostName}")
    public ModelAndView getHost(@PathVariable("hostName") String hostName){
        Host host = hostDAO.getHost(hostName);
        objects.put("host", host);
        return createJson();
    }
}
